#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include "String.h"

_String String;

string String_Format(string format, ...)
{
    int length;
    string str;
    va_list args;

    str = (string)malloc(32767);
    va_start(args, format);
    length = vsprintf(str, format, args);
    va_end(args);

    str = (string)realloc(str, length + 1);
    str[length] = 0;

    return str;
}
string String_Substring(string this, int startIndex, int length)
{
    string str;

    str = (string)malloc(length + 1);
    memcpy(str, this + startIndex, length);
    str[length] = 0;

    return str;
}
bool String_Equals(string this, string value)
{
    return !strcmp(this, value);
}
int String_Length(string this)
{
    return strlen(this);
}

void InitString()
{
    String.Format = String_Format;
    String.Substring = String_Substring;
    String.Equals = String_Equals;
    String.Length = String_Length;
}
